package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateUserInfoDTO;
import com.itlong.cloud.POJO.DTO.operate.OperateUserInfoGetPageDTO;
import com.itlong.cloud.POJO.PO.OperateUserInfoPO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.operate.OperateEngineerProjectVO;
import com.itlong.cloud.POJO.VO.operate.OperateUserInfoGetOneVO;
import com.itlong.cloud.POJO.VO.operate.OperateUserInfoGetUserPageVO;
import com.itlong.cloud.operate.service.IOperateUserInfoService;
import com.itlong.cloud.user.operate.IOperateUserInfoServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * <desc>
 *      运营-系统-用户业务处理处理暴露接口实现类
 * </desc>
 *
 * @createDate 2017/09/28
 */
@RestController
public class OperateUserInfoServiceResource implements IOperateUserInfoServiceClient {
    @Autowired
    IOperateUserInfoService iOperateUserInfoService;

    /**
     * <desc>
     *      修改密码
     * </desc>
     *
     * @param userName 用户名
     * @param password 密码
     * @param newPassword 新密码
     * @return
     * @author Jiaqi.X
     * @createDate 2017/10/13
     */
    @Override
    @RequestMapping(path = "/operate/system/user/updatePassword")
    public Integer updatePassword(
            @RequestParam("userName")String userName,@RequestParam("password")String password,@RequestParam("newPassword")String newPassword) throws Exception {
        return iOperateUserInfoService.updatePassword(userName,password,newPassword);
    }

    /**
     * <desc>
     *      保存人员
     * </desc>
     *
     * @param operateUserInfoPO 人员实体
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @RequestMapping(path = "/operate/system/user/save")
    @Override
    public Integer save(@RequestBody OperateUserInfoPO operateUserInfoPO) throws Exception {
            return iOperateUserInfoService.save(operateUserInfoPO);
}
    /**
     * <desc>
     *      更新人员
     * </desc>
     *
     * @param operateUserInfoPO 人员实体
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @RequestMapping(path = "/operate/system/user/update")
    @Override
    public Integer update(@RequestBody OperateUserInfoPO operateUserInfoPO) throws Exception {
        return iOperateUserInfoService.update(operateUserInfoPO);
    }

    /**
     * <desc>
     *      获取所有人员
     * </desc>
     *
     * @return  人员实体集合
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @RequestMapping(path = "/operate/system/user/getList")
    @Override
    public List<OperateUserInfoPO> getList() {
        return iOperateUserInfoService.getList();
    }

    /**
     * <desc>
     *      获取分页数据
     * </desc>
     *
     * @param pageDTO   参数DTO
     * @return  分页模型
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @RequestMapping(path = "/operate/system/user/getPage")
    @Override
    public Page<OperateUserInfoGetUserPageVO> getPage(@RequestBody OperateUserInfoGetPageDTO pageDTO) throws Exception {
        return iOperateUserInfoService.getPage(pageDTO);
    }

    /**
     * <desc>
     *      根据id查询人员
     * </desc>
     *
     * @param operateGroupPO 人员实体
     * @return  人员实体
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @RequestMapping(path = "/operate/system/user/getOne")
    @Override
    public OperateUserInfoPO getOne(@RequestBody OperateUserInfoPO operateGroupPO) {
        return iOperateUserInfoService.getOne(operateGroupPO);
    }

    /**
     * <desc>
     *      根据id查询人员VO
     * </desc>
     *
     * @param operateUserInfoPO 人员实体
     * @return  人员管理查看人员VO类
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @RequestMapping(path = "/operate/system/user/getOneVO")
    @Override
    public OperateUserInfoGetOneVO getOneVO(@RequestBody OperateUserInfoPO operateUserInfoPO) throws Exception{
        return iOperateUserInfoService.getOneVO(operateUserInfoPO);
    }

    /**
     * <desc>
     *      删除用户
     * </desc>
     * @param userIds   用户id 多个用,号分隔
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/28
     */
    @RequestMapping(path = "/operate/system/user/delete")
    @Override
    public Integer delete(@RequestParam("userIds") String userIds) throws Exception {
        return iOperateUserInfoService.delete(userIds);
    }


    /**
     * <desc>
     *      重置用户密码
     * </desc>
     *
     * @param userIds 用户id数组
     * @return
     * @author Jiaqi.X
     * @createDate 2017/10/12
     */
    @RequestMapping(path = "/operate/system/user/resetPassword")
    @Override
    public Integer resetPassword(@RequestParam("userIds")String userIds) throws Exception {
        return iOperateUserInfoService.resetPassword(userIds);
    }

    /**
     * <desc>
     *      用户登录验证设置缓存信息
     * </desc>
     *
     * @param userInfo 用户实体
     * @return
     * @author Jiaqi.X
     * @createDate 2017/10/12
     */
    @RequestMapping(path = "/operate/system/user/login")
    @Override
    public OperateUserInfoPO login(@RequestBody OperateUserInfoPO userInfo)throws UnsupportedEncodingException {
        return iOperateUserInfoService.login(userInfo);
    }

    /**
     * <desc>
     *      从缓存中获取用户信息
     * </desc>
     *
     * @param token 用户token
     * @return
     * @author Jiaqi.X
     * @createDate 2017/10/13
     */
    @RequestMapping(path = "/operate/system/user/retrieve")
    @Override
    public OperateUserInfoPO retrieve(@RequestParam("token") String token) {
        return iOperateUserInfoService.retrieve(token);
    }

    /**
     * <desc>
     *      从缓存中获取用户信息
     * </desc>
     *
     * @param token 用户token
     * @return
     * @author Jiaqi.X
     * @createDate 2017/10/12
     */
    @RequestMapping(path = "/operate/system/user/newRetrieve")
    public OperateUserInfoPO newRetrieve(@RequestParam("token") String token,@RequestParam("sessionId") String sessionId){
        return iOperateUserInfoService.newRetrieve(token,sessionId);
    }

    /**
     * <desc>
     *      注销用户
     * </desc>
     *
     * @param token
     * @author Jiaqi.X
     * @createDate 2017/10/12
     */
    @RequestMapping(path = "/operate/system/user/cancel")
    @Override
    public void cancel(@RequestParam("token") String token) {
        iOperateUserInfoService.cancel(token);
    }

    /**
     * <desc>
     *      检查账号是否被锁定
     * <desc/>
     * @param  account  检查的账号
     * @return  标准化响应结果
     * @author Juguang.S
     * @createDate 2018/07/18
     */
    @PostMapping(path = "/operate/system/user/getAccountLockDetail")
    @Override
    public MessageVO getOperateAccountLockDetail(@RequestParam("account") String account) {
        return iOperateUserInfoService.getOperateAccountLockDetail(account);
    }

    /**
     * <desc>
     *      运营登陆错误处理
     * <desc/>
     * @param   userInfo    登录用户DTO
     * @return  标准化响应结果
     * @author Juguang.S
     * @createDate 2018/07/18
     */
    @PostMapping(path = "/operate/system/user/loginErrorHandler")
    @Override
    public MessageVO loginErrorHandler(@RequestBody OperateUserInfoPO userInfo) {
        return iOperateUserInfoService.loginErrorHandler(userInfo);
    }

    /**
     * <desc>
     *      判断原密码是否正确
     * <desc/>
     * @param   userId
     * @param   oldPassword
     * @return  标准化响应结果
     * @author Juguang.S
     * @createDate 2019/03/31
     */
    @Override
    @PostMapping(path = "/operate/system/user/isUserOldPsdExist")
    public List<OperateUserInfoPO> isUserOldPsdExist(@RequestParam("userId") String userId,@RequestParam("oldPassword") String oldPassword) {
        return iOperateUserInfoService.isUserOldPsdExist(userId,oldPassword);
    }

    /**
     * <desc>
     *      用户所属角色是否是工程部管理员
     * <desc/>
     * @param   userId
     * @return  标准化响应结果
     * @author Juguang.S
     * @createDate 2020/07/06
     */
    @Override
    @PostMapping(path = "/operate/system/user/isEngineerManage")
    public Integer isEngineerManage(@RequestParam("userId") String userId){
        return iOperateUserInfoService.isEngineerManage(userId);
    }

    /**
     * <desc>
     *      获取用户信息
     * </desc>
     *
     * @param userName 用户名
     * @return
     * @Author Zhu.yj
     * @createDate  2020/8/25
     */
    @PostMapping("/sdk/operate/user/getUserByUserName")
    public OperateUserInfoPO getUserByUserName(@RequestParam("userName") String userName) throws Exception{
        return iOperateUserInfoService.getUserByUserName(userName);
    }

    /**
     * <desc>
     *      获取工程人员项目列表
     * </desc>
     *
     * @return
     * @Author Zhu.yj
     * @createDate  2021/2/1
     */
    @Override
    @PostMapping("/operate/system/user/getEngineerProjectList")
    public List<OperateEngineerProjectVO> getEngineerProjectList(@RequestBody OperateUserInfoDTO operateUserInfoDTO) throws Exception {
        return iOperateUserInfoService.getEngineerProjectList(operateUserInfoDTO);
    }

}
